import config from "@/config/config.js";
import http from "@/api/http.js";


const materialItemRequest = {
    loadMaterials(MaterialDetect,page=1,limit=10,callBack){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.defectBaseUrl + "/materialItem/list?page="+page + "&limit="+limit;
            if(MaterialDetect){
                if (MaterialDetect.templateId){
                    url += "&detectionId=" + MaterialDetect.templateId;

                }
                if(MaterialDetect.templateName){
                    url += "&detectionName=" + MaterialDetect.templateName;
                }
                if (MaterialDetect.templateType){
                    url += "&defectType=" + MaterialDetect.templateType;
                }
            }
            http.get(url,callBack);
        }else {
            callBack(undefined);
        }
    },
    saveMaterialItem(MaterialDetect,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.defectBaseUrl + "/materialItem/save";
            http.post(url,MaterialDetect,callBack);
        }else {
            callBack(undefined);
        }
    },
    updateMaterialItem(MaterialDetect,callBack) {
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.defectBaseUrl + "/materialItem/update";
            http.put(url,MaterialDetect,callBack);
        } else {
            callBack(undefined);
        }
    },
    selectById(materialId,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.defectBaseUrl + "/materialItem/get?materialId=" + materialId;
            http.get(url,callBack);
        }else {
            callBack(undefined);
        }
    },






}

export default materialItemRequest